<?php echo $this->Session->flash(); ?>
<?php
//definición de variables a utilizar
$totalCertificadas = 0;
$totalOtras = 0;
?>
<table width="100%"  >
    <thead style="background:#9097E8">
        <tr>
            <th>Tipo</th>
            <th>Valor</th>
            <th>Clase</th>
            <th colspan="2">Opciones</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($contrapartes as $contraparte): ?>
            <tr style="background-color: #CCC5DB">
                <?php
                if($contraparte['Counterpart']['tipo']=="Certificada"){
                    $totalCertificadas += $contraparte['Counterpart']['valor'];
                }elseif($contraparte['Counterpart']['tipo']=="Otra"){
                    $totalOtras  += $contraparte['Counterpart']['valor'];
                }
               
                ?>
                <td>
                    <?php echo $contraparte['Counterpart']['nombre'] ?>
                </td>
                <td>
                    <?php echo number_format($contraparte['Counterpart']['valor'], 2, ',', '.') ?>
                </td>
                <td>
                    <?php echo $contraparte['Counterpart']['clase'] ?>
                </td>
                <td>
                    <br>
                    <?php echo $ajax->link('Editar', array('controller' => 'counterparts', 'action' => 'edit', $contraparte['Counterpart']['id']), array('class' => 'actions', 'update' => 'contrapartidas', 'indicator' => 'loading', 'escape' => false)); ?>
                    <br>
                    <br>
                </td>
                <td>
                    <br> 
                    <?php echo $ajax->link('Eliminar', array('controller' => 'counterparts', 'action' => 'delete', $contraparte['Counterpart']['id'], $final_evaluation_id), array('class' => 'actions', 'update' => 'contrapartidas', 'indicator' => 'loading', 'escape' => false), '¿Realmente desea eliminar el registro?'); ?>
                    <br>    
                    <br>    
                </td>
            </tr>
        <?php endforeach; ?>
        <tr style="background-color: #CCC5DB">
            <td><b>Total Certificadas ($):</b></td>
            <td><?php echo number_format($totalCertificadas, 2, ',', '.'); ?></td>
            <td colspan="3"></td>
        </tr>
        <tr style="background-color: #CCC5DB">
            <td><b>Total Otras ($):</b></td>
            <td><?php echo number_format($totalOtras, 2, ',', '.'); ?></td>
            <td colspan="3"></td>
        </tr>
        <tr style="background-color: #CCC5DB">
            <td><b>Total Contrapartidas ($):</b></td>
            <td><?php echo number_format($totalOtras + $totalCertificadas, 2, ',', '.'); ?></td>
            <td colspan="3"></td>
        </tr>
    </tbody>
</table>
<br>
<br>
<?php echo $ajax->link('Adicionar', array('controller' => 'counterparts', 'action' => 'add', $final_evaluation_id), array('class' => 'actions', 'update' => 'contrapartidas', 'indicator' => 'loading', 'escape' => false)); ?>